import axios from "@/util/http";

let constArray: any[] = [];

export default {
  state: {
    table_list: [],
    unclear_table_list: [],
  },
  getters: {},
  mutations: {
    setTableList(state, data) {
      state.table_list = data;
    },
    setUnclearTableList(state, data) {
      state.unclear_table_list = data;
    },
  },
  actions: {
    get_all_table(context, data) {
      const url = "/table/get/all/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        context.commit("setTableList", resp.data.data);
        const unclear_table_list = constArray;
        resp.data.data.forEach((item) => {
          if (item.status == 1) {
            unclear_table_list.push(item);
          }
        });
        context.commit("setUnclearTableList", unclear_table_list);
        constArray = [];
        // console.log(context.state.unclear_table_list);
      });
    },
    modify_table_inf(context, data) {
      const url = "/table/modify/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    add_table(context, data) {
      const url = "/table/add/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    delete_table(context, data) {
      const url = "/table/delete/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
  },
  modules: {},
};
